package com.lzl.edu.config;

import com.lzl.edu.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <h3>lzl_ws</h3>
 * <p>拦截器注册类</p>
 *
 * @author : 黎钟龙
 * QQ:1661548820
 * Mail：1661548820@qq.com
 * @date : 2022-03-30 20:58
 **/
@Configuration
public class MvcConfig implements WebMvcConfigurer {
//    注册拦截器
    @Bean
    public MyInterceptor myInterceptor(){
        return new MyInterceptor();
    }

//    对访问路径进行拦截
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        "/*" 对一级访问进行拦截，对二级访问不进行拦截,对Index放行
        registry.addInterceptor(myInterceptor())
                                                .addPathPatterns("*");

//                                                .addPathPatterns("/*")
//                "/*/*"对二级访问进行拦截
//                                                .addPathPatterns("/*/*");
    }
//    添加图片回显路径

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        将访问路径问"/tmp/**"的路径换为本机文件路径
        registry.addResourceHandler("/tmp/**").addResourceLocations("file:/E://tmp//");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
